
using QdbUnit;
using QdbUnit.Extensions;
using Qdb.Ext;
using Qdb.Internal;
using Qdb.Tests.Common.Header;

namespace Qdb.Tests.Common.Header
{
	public class IdentityTestCase : AbstractQdbTestCase
	{
		public static void Main(string[] arguments)
		{
			new IdentityTestCase().RunAll();
		}

		public virtual void TestIdentitySignatureIsNotNull()
		{
			QdbDatabase identity = Db().Identity();
			Assert.IsNotNull(identity.GetSignature());
		}

		/// <exception cref="System.Exception"></exception>
		public virtual void TestIdentityPreserved()
		{
			QdbDatabase ident = Db().Identity();
			Reopen();
			QdbDatabase ident2 = Db().Identity();
			Assert.IsNotNull(ident);
			Assert.AreEqual(ident, ident2);
		}

		/// <exception cref="System.Exception"></exception>
		public virtual void TestGenerateIdentity()
		{
			if (IsMultiSession())
			{
				return;
			}
			byte[] oldSignature = Db().Identity().GetSignature();
			GenerateNewIdentity();
			Reopen();
			ArrayAssert.AreNotEqual(oldSignature, Db().Identity().GetSignature());
		}

		private void GenerateNewIdentity()
		{
			((LocalObjectContainer)Db()).GenerateNewIdentity();
		}
	}
}
